package nl.mvvenrooij.recommended.twitter;

import nl.mvvenrooij.recommended.twitter.data.Status;
import nl.mvvenrooij.recommended.twitter.data.URLEntity;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class RecommendedLinks {

    private Twitter twitter;

    public RecommendedLinks(Twitter twitter) {
        this.twitter = twitter;
    }

    public List<URL> last5Links() {
        List<URL> urls = new ArrayList<URL>();
        //get last tweets parse the tweets till you have 5 links:
        List<Status> statuses = twitter.lastTweets();
        for(Status status : statuses) {
            if(status.getEntities()!=null) {
                for(URLEntity entity : status.getEntities().getUrls()) {
                    urls.add(entity.getUrl());
                    if(urls.size() == 5) {
                        return urls;
                    }
                }
            }

        }
        return urls;
    }
}
